<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>管理员查询用户列表</title>
  <style></style>
</head>

<body>
  <div class="center">
    <div class="list">
      <h3>管理员查询用户列表</h3>
      <table border="1">
        <thead>
          <tr>
            <th>编号</th>
            <th>用户名</th>
            <th>手机号</th>
            <th>年级</th>
            <th>性别</th>
            <th>省份</th>
            <th>邮箱</th>
          </tr>
        </thead>
        <tbody id="show">
        </tbody>
      </table>
      <br>
      <a href="./adminquery.html">针对单一用户查询</a>
    </div>
  </div>
  <script>
    var show = document.getElementById('show')
    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status >= 200 & xhr.status < 300) {
          var result = JSON.parse(xhr.responseText)
          console.log(result)
          show.innerHTML = getlist(result.data)
        }
      }
    }
    xhr.open('GET', '/admin/list', true)
    xhr.send()

    function getlist(data) {
      var str = ``
      for (var i = 0; i < data.length; i++) {
        str += `<tr>
        <td>${data[i].u_id}</td>
        <td>${data[i].unames}</td>
        <td>${data[i].phone}</td>
        <td>${data[i].grade}</td>
        <td>${data[i].gender}</td>
        <td>${data[i].province}</td>
        <td>${data[i].email}</td>
        </tr>`
      }
      return str
    }
  </script>
</body>
</html>